package com.heima.schedule.feign;

import com.heima.feign.schedule.ITaskClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.dtos.TaskDto;
import com.heima.schedule.service.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Lijx
 * @Date 2024-07-26 9:58
 */
@RestController
@Slf4j
public class TaskClient implements ITaskClient {

    @Autowired
    private TaskService taskService;

    /**
     * 添加任务
     * @param taskDto
     * @return
     */
    @Override
    @PostMapping("/api/v1/task/addTask")
    public ResponseResult addTask(TaskDto taskDto) {
        log.info("添加任务接口，入参={}",taskDto);
        return taskService.addTask(taskDto);
    }


    /**
     * 根据任务优先级和类型拉取任务数据
     * @param taskType
     * @param priority
     * @return
     */
    @Override
    @GetMapping("/api/v1/task/{taskType}/{priority}")
    public ResponseResult pullTask(Integer taskType, Integer priority) {
        log.info("定时拉取任务数据中....");
        return taskService.pullTask(taskType,priority);
    }
}
